Inheritance in Object Oriented Programming
Inheritance provides a powerful and natural mechanism for organizing
and structuring software. Classes inherit state and behaviour from their
superclasses, and explains how to derive one class from another using the
simple syntax provided by the Java programming language. In object-oriented
programming, inheritance is a way to form new classes (instances of which are
called objects) using classes that have already been defined.
The new classes, known as derived classes, take over (or inherit)
attributes and behaviour of the pre-existing classes, which are referred to
as base classes (or ancestor classes). It is intended to help reuse existing
code with little or no modification.
Inheritance provides the support for representation by categorization
in computer languages. Categorization is a powerful mechanism number of
information processing, crucial to human learning by means of generalization
(what is known about specific entities is applied to a wider group given a
belongs relation can be established) and cognitive economy (less information
needs to be stored about each specific entity, only its particularities).
An advantage of inheritance is that modules with sufficiently similar
interfaces can share a lot of code, reducing the complexity of the program.
Inheritance therefore has another view, a dual, called polymorphism, which
describes many pieces of code being controlled by shared control code.
Inheritance is typically accomplished either by overriding (replacing) one or
more methods exposed by ancestor, or by adding new methods to those exposed
by an ancestor.
|